<?php
include("conexao.php");

function lista_cursos($tipo, $dia){

    $sql = "SELECT DISTINCT t1.img,
                    t1.nom_cur,
                    t1.idcurso,
                    (SUBSTRING((t3.horario::time)::text,0,6) || ' as ' || SUBSTRING((t4.horario::time)::text,0,6)) AS horario
              FROM curso AS t1
              JOIN horario_sala AS t2 ON (t1.idcurso = t2.idcurso)
              JOIN horario AS t3 ON (t2.idhorario = t3.idhorario)
              JOIN horario AS t4 ON (t2.hor_fim = t4.idhorario)
             WHERE t1.tipo = '{$tipo}' AND t3.dia = '{$dia}'";

    $con = conexao();
    $res = pg_query($con, $sql);
    $miniCursos = array();
    while($row = pg_fetch_assoc($res)){
        $miniCursos[] = $row;
    }
    desconecta($con);
    return $miniCursos;
}

?>
